<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>verifychain</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/css/public.css" >
    <link rel="stylesheet" href="/admin/css/common.css" />
    <link rel="stylesheet" href="/layui/css/layui.css" />
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <!--<form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="realName" placeholder="" class="layui-input">
                </div>
                <label class="layui-form-label">账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>-->
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-table"
               lay-data="{ cellMinWidth: 80, page: true,id:'tableId', limit:10, url:'https://test.ellipticcurve.com.cn:8083/test/queryAllPage', defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],skin: 'line',toolbar: '#user-toolbar'}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox', fixed: 'left'}">ID</th>
                <th lay-data="{field:'id', sort: true,width:60}">ID</th>
                <th lay-data="{field:'jsonString'}">数据体</th>
                <th lay-data="{field:'hashValue'}">数据HashValue值</th>
                <th lay-data="{field:'txTimeStamp'}">上链日期</th>
                <th lay-data="{field:'option', fixed: 'right',width:200,  align: 'center',toolbar:'#optionTp1',unresize: true}">
                    操作
                </th>
            </tr>
            </thead>
        </table>
    </div>
</div>

<script type="text/html" id="optionTp1">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">hashValue验证</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">data验证</a>
</script>



<script src="/js/layui/layui.all.js"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['table', 'jquery', 'form'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var userActivate = 0;
        var userId = 0;

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.confirm(data.hashValue, {icon: 3, title:'verify bolockchain by hashValue?'}, function(index){
                    //do something
                    $.ajax({
                        async : false,
                        url: "https://test.ellipticcurve.com.cn:8083/test/verifyHashValue",
                        type: "post",
                        dataType : "json",
                        data: {"hashValue" : data.hashValue},
                        headers : {
                            "Authorization" :"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTU5Nzc2MTYzNywiaWF0IjoxNTk3NzQzNjM3fQ.8vQ-U0QHfB0Ss6fDRRGpdwhB5ra7cvhYOVt31lL_Ii4P5UjqXf_XUbJZBaj82_yN9iwN1J6LBQLJWWobM3MaEw",
                            "Content-Type" : "application/x-www-form-urlencoded"
                        },
                        success: function (result) {
                            console.log(result);
                            console.log(result.msg);
                            parent.layer.open({
                                title:"blockchain info",
                                content:result.msg
                            })
                        },error: function (err) {
                            parent.layer.msg("验证区块链失败 ！")
                        }

                    })
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                var jsonStr=data.jsonString;
                layer.confirm(JSON.stringify(jsonStr), {icon: 3, title:'verify bolockchain by data?'}, function(index){
                    //do something

                    $.ajax({
                        async : false,
                        url: "https://test.ellipticcurve.com.cn:8083/test/verifyData",
                        type: "post",
                        dataType : "json",
                        data: JSON.stringify(jsonStr),
                        headers : {
                            "Authorization" :"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTU5Nzc2MTYzNywiaWF0IjoxNTk3NzQzNjM3fQ.8vQ-U0QHfB0Ss6fDRRGpdwhB5ra7cvhYOVt31lL_Ii4P5UjqXf_XUbJZBaj82_yN9iwN1J6LBQLJWWobM3MaEw",
                            "Content-Type" : "application/json"
                        },
                        success: function (result) {
                            console.log(result);
                            console.log(result.msg);
                            parent.layer.open({
                                title:"blockchain info",
                                content:result.msg
                            })
                        },error: function (err) {
                            parent.layer.msg("验证区块链失败 ！")
                        }
                    })
                    layer.close(index);
                });
            }
        });
    });
</script>
</body>
</html>